package nsqlib

import (
	"github.com/nsqio/go-nsq"
	"t/log"
)

type ConsumerServer struct{
	consumer *nsq.Consumer
}

func NewConsumer(topic,channel string) error {
	c := new(ConsumerServer)
	conf := nsq.NewConfig()
	var err error
	c.consumer, err = nsq.NewConsumer(topic, channel, conf)
	if err != nil {
		log.Zlog.Error("consumer faild:"+err.Error())
		return err
	}

	m := new(MessageH)
	c.consumer.AddHandler(m)

	err = c.consumer.ConnectToNSQLookupd("192.168.33.11:4161")
	if err != nil {
		log.Zlog.Error("lookup faild:"+err.Error())
		return err
	}

	var g chan struct{}
	<-g
	return nil
}
